package com.qingcheng.controller;

import com.qingcheng.pojo.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ProjectName: qingcheng_parent
 * @ClassName: BaseExceptionHandler
 * @Time: 2019/6/22
 * @Author: zhou24
 * @Description:
 * @Experience:
 */
@ControllerAdvice
public class BaseExceptionHandler {

    /**
     * @ExceptionHandler(Exception.class)
     * Exception.class监听的异常类型
     * ResponseBody转json
     * @param e 异常
     * @return Result
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        System.out.println("调用了公共异常处理类");
        return new Result(1,e.getMessage());
    }

}
